package com.ruoyi.cms.controller.website;

import com.ruoyi.cms.domain.CmsDict;
import com.ruoyi.cms.service.ICmsDictService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 系统字典Controller
 *
 * @author houyong
 * @date 2025-11-08
 */
@Tag(name = "CmsDictController", description = "学科及专业等字典配置")
@RestController
@RequestMapping("cms/website/dict")
public class CmsDictController extends BaseController {
    @Autowired
    private ICmsDictService cmsDictService;

    /**
     * 查询系统字典列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmsDict cmsDict) {
        startPage();
        List<CmsDict> list = cmsDictService.selectCmsDictList(cmsDict);
        return getDataTable(list);
    }

    /**
     * 导出系统字典列表
     */
    @GetMapping("/all/list")
    public AjaxResult export(HttpServletResponse response, CmsDict cmsDict) {
        List<CmsDict> list = cmsDictService.selectCmsDictList(cmsDict);
        Map<String, List<CmsDict>> collect = list.stream().collect(Collectors.groupingBy(
                CmsDict::getDictType
        ));
        return success(collect);
    }


    //TODO 目前系统支持的语言


}
